package com.platform.sys.modular.syncdata.executor.factory;

import com.platform.sys.modular.syncdata.enums.TargetStrategyEnum;
import com.platform.sys.modular.syncdata.executor.abs.SyncDataStrategy;

import java.util.HashMap;
import java.util.Map;

/**
 * 单例+饿汉(注册表)
 */
public class SyncDataFactory {

    private static Map<Integer, SyncDataStrategy> register = new HashMap<>();

    static {
        for (TargetStrategyEnum p : TargetStrategyEnum.values()) {
            register.put(p.getStrategyCode(), p.getPaymentStrategy());
        }
    }

    public static SyncDataStrategy getInstance(Integer code) {
        if (register.containsKey(code)) {
            return register.get(code);
        }
        return null;
    }

}
